//引入必要模块
const express = require('express');
const mysql = require('../mysql');

//建立路由组
const router = express.Router();

//管理员登录
router.get('/login/:aname&:apwd',(req,res)=>{
    let body = req.params;
    //执行sql命令
    mysql.query('select * from sh_admin where admin_name=? and password=?',[body.aname,body.apwd],(err,result)=>{
        if(err) throw err;
        if(result.length != 0){
            return res.send('1');
        }
        res.send('0');
    });
});

//用户列表
router.get('/user/list',(req,res)=>{
    //执行sql命令
    mysql.query('select * from sh_user where is_del=0',[],(err,result)=>{
        if(err) throw err;
        if(result.length != 0){
            return res.send(result);
        }
        res.send('0');
    });
});

//删除用户数据
router.post('/user_delete',(req,res)=>{
    let body = req.body;
    // console.log(body);
    
    mysql.query('update sh_user set is_del=1 where uid=?',[body.uid],(err,result)=>{
        if(err) throw err;
        if(result.affectedRows!=0){
            return res.send('1');
        }
        res.send('0');
    });
});

//导出路由组
module.exports = router;